package com.qf.com.qf.grass.controller;

import com.qf.com.qf.grass.param.AddGrassParam;
import com.qf.com.qf.grass.param.GrassPageParam;
import com.qf.com.qf.grass.service.GrassService;
import com.qf.com.qf.grass.vo.GrassVO;
import com.qf.common.core.annotation.NoLogin;
import com.qf.common.core.common.PageParam;
import com.qf.common.core.common.PageVO;
import com.qf.common.core.entity.Grass;
import com.qf.common.core.utils.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/3/26
 */
@RestController
@RequestMapping("/article")
public class GrassController {
    @Resource
    private GrassService grassService;

    @PostMapping("/add")
    public R<?> addGrass(@RequestBody AddGrassParam addGrassParam) {
        grassService.addGrass(addGrassParam);
        return R.ok("添加成功");
    }

    @GetMapping("/page")
    public R<?> grassPage(GrassPageParam pageParam) {
      PageVO<GrassVO> pageVO = grassService.grassPage(pageParam);
      return R.ok(pageVO);

    }
    @PostMapping("/upload/img")
    public R<?> uploadAvatar(MultipartFile file){
        String imgPath = grassService.uploadImg(file);
        return R.ok(imgPath);
    }

    @NoLogin
    @PostMapping("/timer/add")
    public R<?> timerAddGrass(@RequestBody AddGrassParam addGrassParam) {
        grassService.timerAddGrass(addGrassParam);
        return R.ok("添加成功");
    }
}
